Fix for Array index out of bounds#807
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 973fac398d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (requires_value && i + 1 >= args.length) | ||
| { | ||
| throw new IllegalArgumentException ("Missing value for argument: " + arg); |
There was a problem hiding this comment.
Reject option tokens used as missing argument values
The new guard only checks that i + 1 exists, so a missing value in the middle of the CLI can still consume the next flag as data (for example, --ip-address --board-id 1 sets ip_address to --board-id and then skips parsing --board-id because of the later i++). This silently misconfigures inputs instead of reporting a missing value, which is a regression from the intended validation behavior. Consider treating a known flag token in args[i + 1] as an absent value and throwing IllegalArgumentException in that case as well.
Useful? React with 👍 / 👎.
To fix this safely without changing intended behavior, validate that an option requiring a value actually has a following token before reading
args[i + 1]. The best approach here is to add a guard at the top of the loop: whenargs[i]is one of the known value-taking flags andi + 1 >= args.length, throw anIllegalArgumentExceptionwith a clear message. Then, after consuming a value, incrementi(i++) so the value token is not reprocessed as another flag.In
java_package/brainflow/src/main/java/brainflow/examples/Markers.java, updateparse_argsloop body (lines 31–69 region) to:args[i]into a localarg.argis a known flag requiring a value and whether a value exists.argin comparisons and reads fromargs[i + 1].i++;inside each matched branch after assignment/parsing.No new imports or dependencies are needed.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.